<?php
session_start();
require 'authentication.php';
require 'db_con.php';
if(count($_POST) === 0 || isset($_POST['abortDel'])) {
	header("Location: index.php");
	die();
}

//Deletion of tractor goes here
if(isset($_POST['processDel'])) {
	foreach($_POST as $key=>$value) {
		if ($key != 'processDel') {
			$query = "DELETE FROM tractor WHERE tractor_id= $value";
			mysqli_query($db_con, $query);
		}
	}
	header("Location: index.php");
	die();
}

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Tractors</title>
		<link rel="stylesheet" type="text/css" href="style/style.css">
		<script src="formWrapper.js"></script>
	</head>
	<body>';
echo '<div class="wrap">
			<div class="inner_wrap">
				<div class="header"></div>
				<div class="left_menu">
					 <p><a href="index.php">Home</a></p>
				</div>
				<div class="content">';
					echo "<form action='". $_SERVER['PHP_SELF'] . "' method='post'>";
					echo 'Tractors you want to delete: ' . '<br>';
					foreach($_POST as $key=>$value) {
						echo 'Tractor name: ' . $key . '<br>';
						echo '<input type="hidden" name="' . $key . '" value="' . $value . '">';
					}
					echo 'Are you sure you want to proceed?';
					echo "<input type='submit' name='processDel' value='Yes'>";
					echo "<input type='submit' name='abortDel' value='No'>"; 
				echo '</div>	
			</div>		
		</div>';


echo '</body>
		</html>';

?>
